package calorie.com.calorie.contact;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;

import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.request.UpdateReceivingAddressRequest;
import calorie.com.calorie.request.UpdateReceivingNameRequest;
import calorie.com.calorie.request.UpdateReceivingPhoneRequest;
import calorie.com.calorie.response.ResultDTO;
import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by chenxi on 2019/4/9.
 */

public class ReceiveInformationConract extends BasePresent<ReceiveInformationConract.IReceiveInfo> {
    public static class ReceiveInformationPresent extends BasePresent<IReceiveInfo> {
        //修改收货姓名
        public void updateReceivingName(String receivingName,Integer userId){
            UpdateReceivingNameRequest request = new UpdateReceivingNameRequest(userId,receivingName);
            ApiService service = ServiceGenerator.createService(ApiService.class);
            service.updateReceivingName(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if(getView()!= null){
                        getView().getUpdateReceivingNameResult(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }
        //修改收货电话
        public void updateReceivingPhone(String receivingPhone,Integer userId){
            UpdateReceivingPhoneRequest request = new UpdateReceivingPhoneRequest(userId,receivingPhone);
            ApiService service = ServiceGenerator.createService(ApiService.class);
            service.updateReceivingPhone(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if(getView()!= null){
                        getView().getUpdateReceivingPhoneResult(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }
        //修改收货地址
        public void updateReceivingAddress(String receivingAddress, Integer userId) {
            UpdateReceivingAddressRequest request = new UpdateReceivingAddressRequest(receivingAddress, userId);
            ApiService service = ServiceGenerator.createService(ApiService.class);
            service.updateReceivingAddress(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getUpdateReceivingAddressResult(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }


    }

    public interface IReceiveInfo extends IBaseView {
        void getUpdateReceivingNameResult(Response<ResultDTO> response);

        void getUpdateReceivingPhoneResult(Response<ResultDTO> response);
        void getUpdateReceivingAddressResult(Response<ResultDTO> response);
    }
}
